<template>
  <Echart :height="height" width="100%" :options="options" @handleClick="handleClick" />
</template>

<script>
import Echart from '@/components/Echart/index'
import resize from '@/utils/resize'
export default {
  components: { Echart },
  mixins: [resize],
  props: {
    cdata: {
      type: Object,
      default() {
        return {}
      },
    },
    height: {
      type: String,
      default() {
        return '100%'
      },
    },
  },
  data() {
    return {
      chart: null,
      options: {
        title: {
          text: '标题',
          left: 'center',
          bottom: '32%',
        },
        color: ['#4b6eef', '#3abf81'],
        tooltip: {
          trigger: 'item',
          formatter(params) {
            return `${params.marker} ${params.name}:<br/>${params.value}<br/>${params.percent}%`
          },
        },
        legend: {
          show: true,
          bottom: '0%',
          left: 'center',
          orient: 'vertical',
          icon: 'circle',
          itemWidth: 10,
          height: 70
        },
        series: [
          {
            name: '',
            type: 'pie',
            center: ['50%', '30%'],
            radius: ['40%', '60%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'outSide',
              formatter(params) {
                return params.percent + '%'
              },
            },
            labelLine: {
              show: false,
              showAbove: true,
              length: 20,
              length2: 0,
              minTurnAngle: 90,
            },
            emphasis: {
              show: false,
              // label: {
              //   show: true,
              //   fontSize: '14',
              //   fontWeight: 'normal',
              // },
            },
            data: [
              { value: 1048, name: '特别重大' },
              { value: 735, name: '重大' },
              { value: 580, name: '较大' },
              { value: 484, name: '一般' },
            ],
          },
        ],
      },
    }
  },
  watch: {
    cdata: {
      handler(newValue) {
        this.options.title.text = newValue.title
        this.options.legend.height = newValue.legendHeight
        this.options.legend.show = newValue.legendShow
        this.options.color = newValue.color
        this.options.series[0].data = newValue.data
      },
      immediate: true,
      deep: true,
    },
  },
  methods: {
    handleClick(data) {
      this.$emit('handleClick', data)
    },
  },
}
</script>
